<?php

class HasManyAssociation extends Association
{

  public function loadData()
  {
    if (! $this->dataLoaded && ! $this->owner->has($this->name)) {
      $model = $this->getModel();

      $id = $this->owner->id;

      $fk = $this->getForeignKey();

      $targetName = Domain::getObject($this->target)->getName();

      $r = new CustomRepository($this->target);

      $data = $r->findAll(array(
        'where' => "{$fk} = :$fk",
        'data' => array($fk => $id),
      ));

      if (empty($data)) {
        $data = new ArrayObject;
      }

      $this->owner->{$this->name} = $data;

      $this->dataLoaded = true;
    }
  }

}
